home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Non arithmetic integer type.
- Date: 17 Mar 1996 08:45:32 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4ihfjcINNss6@keats.ugrad.cs.ubc.ca>
- References: <4igp11$83a@airdmhor.gen.nz>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4igp11$83a@airdmhor.gen.nz>,
- Simon Hosie <gumboot@airdmhor.gen.nz> wrote:
- > I've been trying to create a data type that holds an int or intlike chunk
- >of data that is incompatible with any other types (to generate errors if
- >someone assumes that it's the same type as an int).. I've found that
- >
- >typedef struct { int Value; } TypeA;
- >typedef struct { int ValueWithADifferentName; } TypeB;
- >
- > makes two compatible types; a variable of TypeA can be assigned to a
- >variable of TypeB without any warnings.. but
-
- Your compiler has a gratuitous extension that allows for structural
- equivalence type checking.
-
- In standard C, structures with a different tag name are different. Structures
- declard with _no tag_ are always incompatible with each other and with other
- structures that have tags.
-
- An assignment between TypeA and TypeB shouldn't even compile.
-
- >typedef struct { int Value; } TypeA;
- >typedef struct { unsigned Value; } TypeB;
- >
- > is incompatible, which is what I want and it works.. but what if I want
- >three or more incompatible types?
-
- Get a compiler that adheres to the standard, or find an option in your compiler
- to make it do so.
-
- --
-
-